﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="style/editor.css">
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script charset="utf-8" src="kindeditor-4.1.10/kindeditor-min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery-form.js"></script>
<script type="text/javascript">
	var editor;
	
	$(document).ready(function(e) {
		
		//$("#ceshitupian").click(function(){
			KindEditor.ready(function(K){
			editor=K.create("#news_content",{
			themtType:'simple',
			allowImageRemote : false
			})	});
		//	$("#ceshitupian").html("gaibian");
		
        //	    });
			//editor.sync();
			
			$("#userpic").change(function(){
				var file_allname = $("#userpic").val();
				
				var file_int=file_allname.lastIndexOf(".");
				var file_format = file_allname.substring(file_int+1,file_allname.length);
				//$("#dis_textarea").html(file_format);
				$("#ceshitupian").html(file_allname);
				if(file_format=="jpg"||file_format=="jpeg"||file_format=="gif"||file_format=="png"||file_format=="bmp"){

					$("#news_content_form").ajaxSubmit({
					url:'uploadpic.php',
					type:'post',
					dataType:'json',
					success:function(data){
						alert(data.result);
						if(data.result=="error_1"){
							//alert("图片格式不正确！");
							$("#userPic").val("");
							$("#display_filename").val("");
						}
						else if(data.result=="error_2"){
							alert("图片不能超过5M！");
							$("#userPic").val("");
							$("#display_filename").val("");
						}
						else{
							$("#display_filename").val(data.filename);
						}
						
					}
				
 				 });
				}
				
			else{		
				alert("图片格式不正确！请选择jpg/gif/bmp/png/jpeg格式的图片");
				$("#userpic").val("");
				$("#display_filename").val("");
			}

		});
			/*
			$("#ceshi_newcontent").click(function(){
			editor.sync();
			//editor.val();
			var text = $("#userpic").val();
			$("#dis_textarea").html(text);
			});
			*/
		});

	
function ifContentUpload(){
	editor.sync();
	var news_title = $("#news_title").val();
	var news_title_length = news_title.length;
	var news_content = $("#news_content").val();
	if(news_title==""||news_content==""){
		if(news_title==""){
			$("#news_title_tishi").html("标题不能为空！");
			alert("标题不能为空！");
		}
		else{
			$("#news_content_tishi").html("内容不能为空！");
			alert("内容不能为空！");
			
		}
		return false;
	}
	if(news_title_length>50){
		$("#news_title_tishi").html("标题长度不能超过50！");
		alert("标题长度不能超过50！");
	}
	return true;
}
</script>
</head>

<body>
<div class="head_all">
	<div class="head">
		<p><a href="#">返回首页</a></p>		
	</div>
    <div style="clear:both"></div>
</div>
<div class="kindeditor">
	<form id="news_content_form" name="news_content_form" enctype="multipart/form-data" action="upload_all.php" method="post" onsubmit="return ifContentUpload()">
    	<p><span class="font-color-red">*</span>新闻标题：<input type="text"  name="news_title" id="news_title"/><span class="font-color-red" id="news_title_tishi"></span></p>
        <p>新闻标题图片(可有可无):
        <a href="javascript:;" class="chosse_file">选择文件
			<input type="file" name="userpic" id="userpic" title="点击选择文件" value="" />
			<input type="text" value="" id="display_filename" name="display_filename" readonly="readonly" />
		</a>
        </p>
        <p><span class="font-color-red">*</span>新闻内容:<span  class="font-color-red" id="news_content_tishi"></span></p>
		<textarea cols="50" id="news_content" style="width: 580px; height: 500px;"  name="news_content" readonly="readonly"></textarea>
        <input type="submit" value="提交新闻稿" id="news_submit" />
	</form>
    <p id="ceshitupian">aaa</p>
</div>
</body>
</html>
